<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>专题添加</legend>
            <div>
                <blockquote class="layui-elem-quote layui-text">
                    1.搜索添加：指定专题别名为【search】；详情标识可自定义（不要使用特殊字符或中文）；功能类型选择【搜索】
                    <br />
                    2.专题添加：专题别名与采集插件列表对应；详情标识与采集插件详情地址标识对应；功能类型选择【专题】
                </blockquote>
                <form class="layui-form layui-form-pane" action="" lay-filter="addplate">

                    <div class="layui-form-item">
                        <label class="layui-form-label">专题名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="title" autocomplete="off" placeholder="请输入专题名称"
                                class="layui-input">
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">专题别名</label>
                            <div class="layui-input-inline">
                                <div class="layui-input-inline">
                                    <input type="text" name="alias" autocomplete="off" placeholder="请输入专题别名"
                                        class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">详情标识</label>
                            <div class="layui-input-inline">
                                <div class="layui-input-inline">
                                    <input type="text" name="sign" autocomplete="off" placeholder="请输入详情标识"
                                        class="layui-input">
                                </div>
                            </div>
                        </div>

                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">采集列表</label>
                            <div class="layui-input-inline">
                                <select name="collist" lay-filter="aihao">
                                    {volist name=":getCatalog(CMS_COLLECTION_PATH)" id="data"}
                                    <option value="{$data}">{$data}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-primary" lay-submit
                                lay-filter="data-method-btn">获取方法</button>
                        </div>
                        <div class="layui-inline" id="collectionMethod"></div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">功能类型</label>
                        <div class="layui-input-inline">
                            <select name="bindtype" lay-filter="aihao">
                                <option value="special">专题</option>
                                <option value="search">搜索</option>
                            </select>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">专题排序</label>
                            <div class="layui-input-inline">
                                <div class="layui-input-inline">
                                    <input type="text" name="sort" autocomplete="off" placeholder="请输入专题排序"
                                        class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">展示首页</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="index" lay-skin="switch" lay-text="ON|OFF">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">启用专题</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="close" lay-skin="switch" lay-text="ON|OFF">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button type="button" class="layui-btn" lay-submit="" lay-filter="addplate">添加</button>
                    </div>
                </form>
            </div>
        </fieldset>
    </div>


</div>


<script id="collectionMethods" type="text/html">

    <label class="layui-form-label">绑定方法</label>
    <div class="layui-input-inline">
        <select name="method" lay-filter="aihao">
            {{#  layui.each(d.data, function(index, item){ }}
            <option value="{{item.val}}">{{item.name}}</option>
            {{#  }); }}
        </select>
    </div>

</script>

<script>
    layui.use(['form', 'laytpl', 'lycms'], function () {
        var form = layui.form
            , layer = layui.layer, lycms = layui.lycms,
            laytpl = layui.laytpl;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(addplate)', function (data) {
            lycms.plateaddOperate(data)
            return false;
        });

        //监听搜索
        form.on('submit(data-method-btn)', function (data) {
            if (data.field.collist == "") {
                layer.msg("采集列表不能为空");
                return;
            }
            var info = new FormData();
            info.append('collist', data.field.collist);
            $.ajax({
                url: "/ask/action/collectionmethod",
                type: "POST",
                timeout: 5000,
                dataType: "json",
                contentType: 'application/x-www-form-urlencoded;charset=utf-8',
                data: info,
                contentType: false, //不设置内容类型
                processData: false, //不处理数据
                success: function (data) {
                    // data = JSON.parse(data);
                    console.log(data);
                    if (data.code == 200) {
                        console.log(data);
                        var getTpl = collectionMethods.innerHTML
                            , view = document.getElementById('collectionMethod');
                        laytpl(getTpl).render(data, function (html) {
                            view.innerHTML = html;
                            form.render();
                        });
                        layer.msg(data.msg, { time: 1000 });
                    } else {
                        layer.msg(data.msg);
                    }
                },
                error: function (XMLResponse) {
                    //异常捕获
                    layer.msg(XMLResponse.responseText);
                }
            });
            return false;
        });

    });
</script>